/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.opencvjava.practise.ocr;

import org.opencv.core.Mat;
import org.springframework.stereotype.Service;

import static com.opencvjava.support.util.CvUtils.imshow;
import static com.opencvjava.support.util.CvUtils.mat;
import static org.opencv.imgproc.Imgproc.COLOR_BGR2GRAY;
import static org.opencv.imgproc.Imgproc.THRESH_OTSU;
import static org.opencv.imgproc.Imgproc.cvtColor;
import static org.opencv.imgproc.Imgproc.threshold;


/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/3/25
 */
@Service
public class TestOcr1 {
    public void test() {
        Mat src = mat("ocr", "1.jpg");
        if (src.empty()) {
            throw new RuntimeException("读取图片失败");
        }
        imshow("源图", src);
        Mat gray = new Mat();
        cvtColor(src, gray, COLOR_BGR2GRAY);
        Mat binary = new Mat();
        threshold(gray, binary, 127, 255, THRESH_OTSU);
        imshow("二值化", binary);
    }
}
